package com.kwm.Aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import java.util.Arrays;

@Component
@Slf4j
@Aspect
public class DeptAscept {

    @Pointcut("execution(* com.kwm.Service.impl.DeptServiceimpl.*(..))")
    public void at() {
    }

    @Before("at()")
    public void befor(JoinPoint joinPoint) {
        log.info("前置通知");

        //1.获取目标类名
        String name = joinPoint.getTarget().getClass().getName();

        System.out.println("name = " + name);
        //2.获取目标方法签名
        Signature method = joinPoint.getSignature();
        System.out.println("method = " + method);
        //3.获取目标方法名
        String name1 = method.getName();
        System.out.println("name1 = " + name1);
        //4.获取方法参数
        Object[] args = joinPoint.getArgs();
        System.out.println("args = " + Arrays.toString(args));

    }

    @Around("at()")
    public Object Everything(ProceedingJoinPoint point) throws Throwable {


        //1.获取目标类名
        String name = point.getTarget().getClass().getName();

        System.out.println("name = " + name);
        //2.获取目标方法签名
        Signature method = point.getSignature();
        System.out.println("method = " + method);
        //3.获取目标方法名
        String name1 = method.getName();
        System.out.println("name1 = " + name1);
        //4.获取方法参数
        Object[] args = point.getArgs();
        System.out.println("args = " + Arrays.toString(args));


        log.info("在这里填充修改的内容");
        Object result = point.proceed();

        return result;
    }


}
